

Berta.SettingsRenderer.addType("text", function() {
	
	return function(params, definition, setting) {
		var html = $('<div class="x-setting">' +
				'<span class="x-setting-caption">' + definition.title + '</span>' + 
				'<span class="x-setting-value">' +
					'<span class="x-editable"></span>' +
				'</span><br class="x-clear" />' +
			'</div>');
		
		var p = Berta.SettingsRenderer.buildEditorParams(
					jQuery.extend(params, {
						'editor': 'Textline',
						'variable': definition.name,
						'route': 'put:' + params.setting_collection
					}), 
					definition
				);
		
		html.find('.x-editable')
			.html((setting && setting.value) ? setting.value : (definition['default'] ? definition['default'] : ''))
			.attr('data-berta', JSON.stringify(p));
			
		return html;
	}
	
}());


Berta.SettingsRenderer.addType("number", function() {
	
	return function(params, definition, setting) {
		var html = $('<div class="x-setting">' +
				'<span class="x-setting-caption">' + definition.title + '</span>' + 
				'<span class="x-setting-value">' +
					'<span class="x-editable"></span>' +
					//("unit" in definition ? (' <span class="x-setting-unit">' + definition.unit + '</span>') : '') + 
				'</span><br class="x-clear" />' +
			'</div>');
			
		var p = Berta.SettingsRenderer.buildEditorParams(
					jQuery.extend(params, {
						'editor': 'Number',
						'variable': definition.name,
						'route': 'put:' + params.setting_collection
					}), 
					definition
				);
		
		html.find('.x-editable')
			.html((setting && setting.value) ? setting.value : (definition['default'] ? definition['default'] : ''))
			.attr('data-berta', JSON.stringify(p));
			
		return html;
	}
	
}());


Berta.SettingsRenderer.addType(["select", "switch", "color"], function() {
	
	return function(params, definition, setting) {
		var html = $('<div class="x-setting">' +
				'<span class="x-setting-caption">' + definition.title + '</span>' + 
				'<span class="x-setting-value">' +
					'<span class="x-editable"></span>' +
				'</span><br class="x-clear" />' +
			'</div>');
			
		var editorPlugin;
		switch(definition.renderType) {
			case 'color': editorPlugin = 'Color'; break;
			case 'switch': editorPlugin = 'OnOff'; break;
			default: editorPlugin = 'Select';
		}
		
		var p = Berta.SettingsRenderer.buildEditorParams(
					jQuery.extend(params, {
						'editor': editorPlugin,
						'variable': definition.name,
						'route': 'put:' + params.setting_collection
					}), 
					definition
				);
		
		html.find('.x-editable')
			.html((setting && setting.value) ? setting.value : (definition['default'] ? definition['default'] : ''))
			.attr('data-berta', JSON.stringify(p));
			
		return html;
	}
	
}());



Berta.SettingsRenderer.addType("file", function() {
	
	return function(params, definition, setting) {
		var html = $('<div class="x-setting">' +
				'<span class="x-setting-caption">' + definition.title + '</span>' + 
				'<span class="x-setting-value">' +
					'<span class="x-editable"></span>' +
				'</span><br class="x-clear" />' +
			'</div>');
			
		var p = Berta.SettingsRenderer.buildEditorParams(
					jQuery.extend(params, {
						'editor': 'File',
						'variable': definition.name,
						'route': 'put:' + params.setting_collection,
						'captionUploading': ''
					}), 
					definition
				);
		
		html.find('.x-editable')
			.append('<div class="x-editable-file-file">' + ((setting && setting.value) ? setting.value : (definition['default'] ? definition['default'] : '')) + '</div>')
			.attr('data-berta', JSON.stringify(p));
			
		return html;
	}
	
}());